package com.lagou.edu.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class IndexController {

    @RequestMapping("/")
    public String queryAll(){
        return "login";
    }


    @RequestMapping("/login")
    @ResponseBody
    public JSONObject login(HttpSession session, String loginName, String loginPassd){
        System.out.println("loggin---"+loginName+":"+loginPassd);
        JSONObject result=new JSONObject();
        if(loginName.equals("admin")&&loginPassd.equals("admin")){
            session.setAttribute("username",loginName);
            result.put("status","200");
        }else{
            session.invalidate();
            result.put("mesage", "FAIL");
        }
        return result;
    }

    @RequestMapping("/logout")
    public String login(HttpSession session) throws Exception {
        session.removeAttribute("username");
        return "redirect:/";
    }

}
